package com.jlcindia.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.jlcindia.util.HibernateUtil;

public class Lab46 {
	public static void main(String args[]) {
		Transaction tx = null;
		try {
			SessionFactory sf = HibernateUtil.getSessionFactory();
			Session session = sf.openSession();
			tx = session.beginTransaction();

			Query q = session.createQuery("from Contact c");
			q.setCacheable(true);
			List<Contact> list = q.list();
			for (Contact c : list) {
				System.out.println(c);
			}

/*			Criteria ct = session.createCriteria(Contact.class);
			ct.setCacheable(true);
			list = q.list();
			for (Contact c : list) {
				System.out.println(c);
			}*/
			
			tx.commit();
			Thread.currentThread().sleep(5000);
			session.close();

		} catch (Exception e) {
			if (tx != null) {
				tx.rollback();
			}
			e.printStackTrace();
		}
	}
}
